package com.javathree;

import java.util.Scanner;

public class Demo3 {
    //存，取--->注册流程:收集用户的信息进行保存到数组中,重名验证,多次注册
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        User[] users = new User[5];
        boolean isflag=true;
        do {
            System.out.println("请输入用户名：");
            String uname = scanner.next();
            System.out.println("请输入密码：");
            String password = scanner.next();

            User user = new User();
            user.name=uname;
            user.password=password;
            user.id=001;
            //验证用户名是否存在
            boolean  b= checkName(users,uname);
            if(b){
                for (int i=0;i<users.length;i++){
                    if(users[i]==null) {
                        users[i]=user;
                        System.out.println("是否继续注册(y/n)");
                        String next = scanner.next();
                        if(!next.equals("y")){
                            isflag=false;
                        }
                        break;
                    }
                }
            }else {
                System.out.println("用户名存在,请重新录入");
            }
        }while (isflag);
        System.out.println("注册成功....");
    }


    public static boolean checkName(User[] users,String name) {
        for (int i = 0; i < users.length; i++) {
            if (users[i] != null) {
                if(users[i].name.equals(name)){
                   return false;
                }
            }
        }
        return true;
    }
}
